<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="/common/tags.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <title>${seo.title}</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta charset="UTF-8">
    <meta name="Keywords" content="${seo.keywords}">
    <meta name="description" content="${seo.description}">
    <%@include file="/common/style.jsp" %>
    <link rel="stylesheet" type="text/css" href="${static_url}/ui/app/assets/css/sub.css">


    <%@include file="/common/javascript.jsp" %>

</head>
<body class="wide">
<!-- 头部 -->
<%@include file="/common/myHeader.jsp" %>
<!-- /头部 -->
<div style="border-top: solid 1px #dcdcdc;" class="h10"></div>

<!-- 主体 -->
<div class="order-header">
    <div class="g">
        <div class="fl">
            <%--<div class="logo">
              <a href="##" title="">
              <img src="##" alt="">
              </a>
            </div>--%>
        </div>
        <div class="fr">
            <!--步骤条-三步骤 -->
            <div class="progress-area progress-area-3">
                <!--我的购物车 -->
                <div id="progress-cart" class="progress-sc-area hide" style="display: block;"></div>
                <!--核对订单 -->
                <div id="progress-confirm" class="progress-co-area hide">填写核对订单信息</div>
                <!--成功提交订单 -->
                <div id="progress-submit" class="progress-sso-area hide">成功提交订单</div>
            </div>
        </div>
    </div>
</div>

<div class="layout">
    <div class="sc-list">
        <div class="sc-pro-list">
            <div class="sc-pro-title-area">
                <div class="h">
                    <table border="0" cellpadding="0" cellspacing="0">
                        <thead>
                        <tr>
                            <th class="tr-check">
                                <%--<input id="checkAll-top" type="checkbox" class="vam" autocomplete="off" onclick="checkAll(this)" checked>--%>
                            </th>
                            <th class="tr-pro">商品</th>
                            <th class="tr-price">单价<em>（万）</em></th>
                            <th class="tr-quantity">数量</th>
                            <%--<th class="tr-subtotal">小计<em>（万）</em></th>--%>
                            <th class="tr-operate">操作</th>
                        </tr>
                        </thead>
                    </table>
                </div>
            </div>
            <form id="cart-form" action="${ctx}/order/confirmcart.htm" autocomplete="off" method="get">
                <input type="hidden" name="state" value="1">
                <span id="cart-list">
                    <!--product-list start-->
                    <c:forEach items="${results.records}" var="goods" varStatus="status">
                    <div class="sc-pro-area selected" id="order-pro-${goods.id}">
                        <table border="0" cellpadding="0" cellspacing="0">
                            <tbody>
                            <tr class="sc-pro-item">
                                <td  class="tr-check">
                                    <input  class="checkbox" type="checkbox"
                                           name="goodsId"
                                           value="${goods.id}" data-type="1" checked="checked">
                                </td>
                                <td class="tr-pro">
                                    <div class="pro-area clearfix">
                                        <p class="p-img">
                                            <a title="" target="_blank"
                                               href="${ctx}/detail.htm?id=${goods.id}" seed="cart-item-name">
                                                <img alt=""
                                                     src="${fileServerUrl}/${goods.photo}">
                                            </a>
                                        </p>

                                        <p class="p-name">
                                            <a title="" target="_blank" href="${ctx}/detail.htm?id=${goods.id}" seed="cart-item-name">
                                                ${goods.name}
                                            </a>
                                        </p>
                                        <p class="p-sku"><em></em></p>
                                    </div>
                                </td>
                                <td class="tr-price"><span>${goods.price}</span></td>
                                <td class="tr-quantity" rowspan="4">
                                    <div class="sc-stock-area">
                                        <div class="stock-area">
                                            <input id="quantity-${goods.id}" type="text" class="shop-quantity textbox vam" value="1"
                                                data-skuid="${goods.id}" data-type="1" seed="cart-item-num" readonly>
                                        </div>
                                        <p class="normalLimitstock-3151 hide"></p></div>
                                </td>
                               <%-- <td  class="tr-subtotal"><b>¥1599.00</b></td>--%>
                                <td  class="tr-operate">
                                    <a href="javascript:;" class="icon-sc-del" title="删除"
                                                                      onclick="deleteOrder('${goods.id}')"
                                                                      seed="cart-item-del">
                                        删除
                                    </a>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                    </c:forEach>
                    <!--product-list end-->
                </span>
            </form>
        </div>
        <div class="h20"></div>
        <div id="cart-total-area" class="sc-total-area clearfix">
            <div class="sc-total-control">
                <input id="checkAll-buttom" type="checkbox" name="" class="vam"
                                                 autocomplete="off" checked onclick="checkAll(this)">
                <label class="vam" for="checkAll-buttom">全选</label>
                <a class="vam" href="javascript:;" seed="cart-all-del">删除选中商品</a>
            </div>
            <div class="sc-total-price">
                <table border="0" cellpadding="0" cellspacing="0">
                    <tbody>
                    <tr>
                        <th>总计金额：</th>
                        <td id="sc-cartInfo-totalOriginalPrice">¥${results.totalPrice}万</td>
                    </tr>
                    <tr>
                        <th>共节省：</th>
                        <td id="sc-cartInfo-minusPrice">¥0.00</td>
                    </tr>
                    <tr>
                        <th><em>合计(不含运费)：<em></em></em></th>
                        <td><b id="sc-cartInfo-totalPrice">¥${results.totalPrice}万<b></b></b></td>
                    </tr>
                    </tbody>
                </table>
            </div>
        </div>
        <div class="h25"></div>
        <div class="sc-action-area clearfix">
            <a class="button-style-4 button-go-shopping-3" href="${ctx}/guide.htm">继续购物</a>
            <a class="button-style-1 button-go-checkout-2" href="javascript:goConfirmCart();" seed="cart-pay">去结算</a>
            <div class="sc-action-tips hide" id="sc-action-tips">
                <div class="tips-style-1 tips-area"><i></i>
                    <div class="tips-text"><p id="tips-text-p">购物车中有库存不足商品，请处理后结算</p></div>
                    <s></s>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    function checkAll(chkSelf){
        var obj = $(chkSelf);
        var id = obj.attr("id");
        if(obj.is(':checked')){
            $("input[name=goodsId]").each(function(){
                this.checked = true;
            });
        }else{
            $("input[name=goodsId]").each(function(){
                this.checked = false;
            });
        }
    }

    function deleteOrder(goodsId){
        if(confirm("确定删除？")){
            $.post("${ctx}/order/deleteGoods.htm",{goodsId:goodsId},function(data){
                if(data.success){
                    console.log(data);
                    $("#order-pro-"+goodsId).remove();
                    $("#sc-cartInfo-totalPrice").text("¥"+data.totalPrice+"万");
                    $("#sc-cartInfo-totalOriginalPrice").text("¥"+data.totalPrice+"万");
                }
            },"json")
        }
    }

    function goConfirmCart(){
        var chk_value =[];//定义一个数组
        $('input[name="goodsId"]:checked').each(function(){//遍历每一个名字为interest的复选框，其中选中的执行函数
            chk_value.push($(this).val());//将选中的值添加到数组chk_value中
        });
        if(chk_value.length>0){
            $("#cart-form").submit();
        }else{
            alert("您的购物车是空的，赶紧选购吧！");
        }
    }
</script>

<!-- /主体 -->

<!-- 底部 -->
<%@include file="/common/footer.jsp" %>
<!-- /底部 -->

</body>
</html>
